﻿@{
    ViewBag.Title = "秒杀活动列表";

}
@section styles{
    <link href="~/static/css/client.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/system.css" type="text/css" rel="stylesheet" />
    <link href="~/static/css/contract.css" type="text/css" rel="stylesheet" />
}
<style>
    a {
        text-decoration: none;
    }

    .brand_logo {
        width: 28px;
        height: 28px;
    }

    .hidden {
        display: none;
    }

    .layui-upload-img {
        max-width: 300px;
        max-height: 200px;
    }
</style>
<div class="layui-fluid layui-content">
    <div class="layui-title layui-clear layui-row">
        <h2 class="layui-col-md10 layui-col-sm9 layui-col-xs7">@ViewBag.Title</h2>
        <div class="layui-col-md2 layui-col-sm3 layui-col-xs5 layui-nav-item">
            <a class="layui-btn layui-btn-xs" onclick="top.NewTab(121514,'添加活动','@Url.Action("Create")')">添加活动</a>
        </div>
    </div>
    <div class="layui-eacher layui-row layui-clear">
        <form class="layui-clear">
            <div class="layui-form layui-clear">
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <label class="layui-form-label">
                        关键词：
                    </label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="keyword" id="keyword" />
                    </div>
                </div>
                <div class="layui-col-md6 layui-col-pc7 layui-col-lg7 layui-form-group">
                    <div class="layui-input-block">
                        <select name="range" id="range" lay-filter="range">
                            <option value="" selected>全部</option>
                            <option value="Going">进行中</option>
                            <option value="Not">未开始</option>
                            <option value="Over">已结束</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-md1">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" id="search" type="button"> 搜索 </button>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-data layui-table-container">
        <table class="layui-hide layui-table" id="layui-table" lay-filter="table"></table>
    </div>
</div>
<div id="Layer_ajax" class="deploy-plus"></div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-sm" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>

@section scripts{
    <script src="~/static/js/jquery.ztree.core.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.excheck.js" type="text/javascript"></script>
    <script src="~/static/js/jquery.ztree.exedit.js" type="text/javascript"></script>
    <script src="~/js/main.js"></script>
    <script type="text/javascript">

        var layer,form, table;
        layui.use(['form', 'layedit', 'laydate','table', 'layer'], function () {
            var /*form = layui.form*/
                layedit = layui.layedit
                , laydate = layui.laydate;

            layer = layui.layer
            form = layui.form;
            table = layui.table;

            table.render({
                elem: "#layui-table",
                url: '@Url.Action("GetSpikeData")',
                cellMinWidth: 26,
                height: 'full-150',
                cols: [[
                    //{ type: 'checkbox' },
                    { field: 'secondkillTitle', title: '秒杀标题'},
                    { field: 'shopProductName', title: '商品名称' },
                    { field: 'secondkillPrice', title: '秒杀价格' },
                    { field: 'secondkillCount', title: '秒杀仓库数' },
                    {
                        field: 'secondkillBeginTime', title: '开始时间', templet: function (d) {
                            var secondkillBeginTime = new Date(d.secondkillBeginTime);
                            return 'secondkillBeginTime', top.dateFtt("yyyy-MM-dd", secondkillBeginTime);
                        }
                    },
                    {
                        field: 'secondkillEndTime', title: '结束时间', templet: function (d) {
                            var secondkillEndTime = new Date(d.secondkillEndTime);
                            return 'secondkillEndTime', top.dateFtt("yyyy-MM-dd", secondkillEndTime);
                        }
                    },
                    { title: '操作', width: 213, align: 'center', toolbar: '#barDemo' }
                ]],
                id: "idTest",
                page: true,
            });
            //监听工具条
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.get("/Promotions/Delete?id=" + data.id, function (obj, successInfo) {
                            CommonAjaxCallback(obj, function () {
                                table.reload('idTest', {
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    }
                                })
                            }, successInfo)
                        })
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    top.NewTab(121515, '编辑-' + data.shopProductName+'秒杀活动', '/Promotions/Edit?id=' + data.id)

                }
            });
            $('#search').on('click', function () {
                table.reload('idTest', {
                    where: {
                        keyword: $('#keyword').val(),
                        range: $('#range').find("option:selected").val()
                    },
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            })


        });


        $("#layui-Area").click(function () {
            $(".layui-Area .layui-Area-hide").toggleClass("layui-Area-show")
            $(this).parent(".layui-form-select").toggleClass("layui-form-selected");
        });

        $(".layui-Area").mouseleave(function () {
            $(".layui-Area .layui-Area-hide").removeClass("layui-Area-show")
        })


        $(document).ready(function () {

        });
        var lock = false;//锁作为全局变量
        function LoadNewOpen(url) {
            if (lock) {
                return false;
            } else {
                lock = true;
            }
            $("#Layer_ajax").load(url, function (responseTxt, statusTxt, xhr) {
                if (statusTxt == "error") {
                    top.layer.msg('页面加载失败！', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }
                form.render('select')
                $.validator.unobtrusive.parse(this);
                var height = $("#Layer_ajax").height();
                layer.open({
                    type: 1,
                    shadeClose: true,
                    title: false,
                    closeBtn: 0,
                    scrollbar: false,
                    content: $("#Layer_ajax"),
                    area: ["600px", height],
                    success: function (layero, index) {
                        //锁关闭
                        lock = false;
                    },
                    end: function () {
                        $("#Layer_ajax").empty();
                    }
                })
            })
        }


        function LayerOpen(title, url) {
            var open = layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['1400px', '800px'],
                content: url,
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index)//确定两个页面的父子关系
                },
                end: function () {
                    //销毁后重新加载
                    table.reload('idTest', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    })
                }
            });
        }

        function ReloadAjaxCallbackgoback(data, successInfo) {
            CommonAjaxCallback(data, function () {
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })
            }, successInfo)
        }


    </script>
}